package com.zw.cloud.tools.event;

import com.zw.cloud.tools.utils.UriUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.*;

@Slf4j
@Component
public class ApplicationStartedEventListener implements ApplicationListener<ApplicationStartedEvent> {

    @Autowired
    Environment environment;

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        log.info("[ApplicationStartedEvent][onApplicationEvent]......");

        List<String> urlList = UriUtils.uriList;
        String osName = environment.getProperty("os.name");
        if (StringUtils.isNotBlank(osName) && !osName.startsWith("Windows")) {
            StringBuffer msg = new StringBuffer("#### 接口url\n");
            for (String url : urlList) {
                msg.append("> 接口url:" + url + " \n\n ");
            }
            //DingTalkUtils.sendDingTalkMsgWithSign("现有接口",msg.toString());
        }
        log.info("[ApplicationStartedEvent][onApplicationEvent]urlList is {}",urlList);
    }


}

